/*
 * Copyright (c) 2015. 石头哥哥
 */

package com.comom.manager.kit.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

    private static final ThreadLocal<SimpleDateFormat> defaultDateFormat =
            new ThreadLocal<SimpleDateFormat>();

    private static final ThreadLocal<SimpleDateFormat> msgDateFormat =
            new ThreadLocal<SimpleDateFormat>();


    private static SimpleDateFormat getDefaultDateFormat() {
        if (null == defaultDateFormat.get()) {
            defaultDateFormat.set(new SimpleDateFormat("yyyy-MM-dd"));//日期格式化
        }
        return defaultDateFormat.get();
    }

    /**
     *
     * @return
     */
    private static SimpleDateFormat getMsgDateFormat() {
        if (null == msgDateFormat.get()) {
            msgDateFormat.set(new SimpleDateFormat("yyyy年MM月dd日 HH时"));//日期格式化  24小时制
        }
        return msgDateFormat.get();
    }





    public static Date parseDate(String date) {
        Date result = null;
        try {
            result = getDefaultDateFormat().parse(date);
        } catch (ParseException e) {
        }
        return result;
    }


    /**
     *
     * @param timestamp
     * @return
     */
    public static String formatMsgDate(long timestamp) {
        return getMsgDateFormat().format(new Date(timestamp));
    }


    /**
     * @param date
     * @return
     */
    public static String format(Date date) {
        return getDefaultDateFormat().format(date);
    }


    public static void main(String[]args){
        System.out.println(formatMsgDate(System.currentTimeMillis()));
    }



}


